/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package JFreeChartExtensions.storable;


import JFreeChartExtensions.Series.XYExtendedIntervalSeries;
import JFreeChartExtensions.Series.XYRegressionSeries;
import java.io.Serializable;
import org.jfree.data.xy.XYIntervalSeries;

/**
 *
 * @author Nobody
 */
public class StorableSeriesObject implements Serializable {

    private Number[] x;
    private Number[] lowX;
    private Number[] highX;
    private Number[] lowY;
    private Number[] highY;
    private Number[] y;
    private String name;
    private boolean reggressionSeries;

    public StorableSeriesObject(XYIntervalSeries series) {
        
        reggressionSeries = series instanceof XYRegressionSeries;
        name = (String) series.getKey();
        int tableSize = series.getItemCount();
        x = new Number[tableSize];
        lowX = new Number[tableSize];
        highX = new Number[tableSize];
        lowY = new Number[tableSize];
        highY = new Number[tableSize];
        y = new Number[tableSize];
        for (int i = 0; i < tableSize; ++i) {
            x[i] = series.getX(i);
            y[i] = series.getYValue(i);
            lowX[i] = series.getXLowValue(i);
            highX[i] = series.getXHighValue(i);
            lowY[i] = series.getYLowValue(i);
            highY[i] = series.getYHighValue(i);
        }
    }

     public StorableSeriesObject() {
    }

    public boolean isReggressionSeries() {
        return reggressionSeries;
    }

    public Number[] getX() {
        return x;
    }

    public Number[] getY() {
        return y;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

   

    public XYIntervalSeries aSXYSeries() {

        XYExtendedIntervalSeries series = createSeries(name);
        for (int i = 0; i < x.length; ++i) {
            series.add((Double) x[i], (Double) lowX[i], (Double) highX[i], (Double) y[i], (Double) lowY[i], (Double) highY[i]);
        }
        return series;
    }

    private XYExtendedIntervalSeries createSeries(String name) {
        return reggressionSeries ? new XYRegressionSeries(name) : new XYExtendedIntervalSeries(name);
    }
}
